package cn.edu.scau.cmi.wurihua.service;

import org.apache.ibatis.session.SqlSession;

import cn.edu.scau.cmi.wurihua.entity.Student;
import cn.edu.scau.cmi.wurihua.entity.Teacher;
import cn.edu.scau.cmi.wurihua.mapper.StudentMapper;
import cn.edu.scau.cmi.wurihua.mapper.TeacherMapper;
import cn.edu.scau.cmi.wurihua.util.MybatisUtil;

public class TeacherService {
	private SqlSession sqlSession = MybatisUtil.getSession();
	private TeacherMapper teacherMapper = sqlSession.getMapper(TeacherMapper.class);
	
	public Teacher selectService(int id) {
		Teacher s = (Teacher)teacherMapper.selectById(id);
		return s;
	}
	public int insertService(Teacher t) {
		try {
			if(teacherMapper.insert(t)>0) {
				sqlSession.commit();
				return 1;
			}	
		}catch (Exception e) {
			// TODO: handle exception
			sqlSession.rollback();
		}
		return 0;
	}
	public int deleteService(int id) {
		try {
			if(teacherMapper.delete(id)>0) {
				sqlSession.commit();
				return 1;
			}
		}catch (Exception e) {
			// TODO: handle exception
			sqlSession.rollback();
		}
		return 0;
	}
	public int updateService(Teacher t) {
		try {
			if(teacherMapper.update(t)>0) {
				sqlSession.commit();
				return 1;
			}
			
		}catch (Exception e) {
			// TODO: handle exception
			sqlSession.rollback();
		}
		return 0;
	}
}
